<%@ page language="java" contentType="text/html; charset=UTF-8"
	pageEncoding="UTF-8"%>
<%@ page import="java.sql.*"%>
<%@ page import="java.net.URLEncoder"%>
<%@ page import="com.model.*"%>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<title></title>
<style type="text/css">
<!--
body {
	background-color: #fff;
	margin-left: 0px;
	margin-top: 0px;
	margin-right: 0px;
	margin-bottom: 0px;
}

.tabfont01 {
	font-family: "宋体";
	font-size: 9px;
	color: #555555;
	text-decoration: none;
	text-align: center;
}

.font051 {
	font-family: "宋体";
	font-size: 12px;
	color: #333333;
	text-decoration: none;
	line-height: 20px;
}

.font201 {
	font-family: "宋体";
	font-size: 12px;
	color: #FF0000;
	text-decoration: none;
}

.button {
	font-family: "宋体";
	font-size: 14px;
	height: 37px;
}

html {
	overflow-x: auto;
	overflow-y: auto;
	border: 0;
}
-->
</style>

<link href="../css/css.css" rel="stylesheet" type="text/css" />
<script type="text/JavaScript">
	
</script>
<link href="../css/style.css" rel="stylesheet" type="text/css" />

<script type="text/JavaScript">
	function selectAll() {
		var obj = document.fom.elements;
		for ( var i = 0; i < obj.length; i++) {
			if (obj[i].name == "delid") {
				obj[i].checked = true;
			}
		}
	}

	function unselectAll() {
		var obj = document.fom.elements;
		for ( var i = 0; i < obj.length; i++) {
			if (obj[i].name == "delid") {
				if (obj[i].checked == true)
					obj[i].checked = false;
				else
					obj[i].checked = true;
			}
		}
	}

	function save() {		
		var obj = document.fom.elements;
		var x = 0;
		for (var i=0; i<obj.length; i++ ){
			if(obj[i].name == "delid"){
				if(obj[i].checked == true){
					x++;
				}
			}
		}
		if(x==0){
			alert("请选择需要回车的车辆");
			return;
		}
		else if(confirm("确定回车选定车辆？")){
			document.fom.submit();	
		}
	}

	function go() {
		if($("#textfield3").val()==""||null){
			alert("请输入页数！");
			$("#textfield3").focus();
			return;
		}
		var jump_page = document.getElementById("jump_page").value;
		location.href = "?pageCar=" + jump_page;
	}
</script>
</head>

<body>
	<%
		int pageNow = 1;
		int pagePrev = 0;
		int pageNext = 0;

		int entityCount = 0;
		int pageSize = 10; //	the number of entities one page contains
							//	set as variable but not constant for future
							//	user-defined function
		int pageTotal = 0;

		request.setCharacterEncoding("UTF-8");
		String pageNowStr = request.getParameter("pageCarBack");

		if (pageNowStr != null)
			pageNow = Integer.parseInt(pageNowStr);
		else
			pageNow = 1;

		Connection con = DataBase.getConnection();

		PreparedStatement pstmtCount = con
				.prepareStatement("SELECT COUNT(*) as count FROM car WHERE status=1");
		ResultSet rs = pstmtCount.executeQuery();
		if (rs.next()) {
			entityCount = rs.getInt("count");
			int mod = entityCount % pageSize;
			if (mod == 0)
				pageTotal = entityCount / pageSize;
			else
				pageTotal = entityCount / pageSize + 1;
		} else {
			pageTotal = 1;
		}
		rs.close();

		if (pageNow > pageTotal || pageNow < 1)
			pageNow = 1;

		if (pageNow > 1)
			pagePrev = pageNow - 1;
		else
			; // initial value is 0

		if (pageNow < pageTotal)
			pageNext = pageNow + 1;
		else
			; // initial value is 0

		//Search Function Support
		String query = request.getParameter("query");
	%>
	<table width="100%" border="0" cellspacing="0" cellpadding="0">

		<tr>
			<td height="30">
				<form name="search" id="search" method="get" action="list_CLHC.jsp">
				<table width="100%" border="0" cellspacing="0" cellpadding="0">
					<tr>
						<td height="62" background="../image/widgetbg5.jpg">

							<table width="98%" border="0" align="center" cellpadding="0"
								cellspacing="0">
								<tr>
									<td width="21"><img src="../images/ico07.gif" width="20"
										height="18" /></td>
									<td width="550">车牌号： <input name="query" id="query" type="text"
										size="12" /><span class="newfont06" /> <input name="Submit"
										type="button" 
										onclick="document.getElementById('search').submit();"
										value="查 询" /></td>
								</tr>
							</table>
						</td>
					</tr>
				</table>
				</form>
			</td>
		</tr>
		<tr>
			<td>
				<form name="fom" id="fom" action="CarDeal?flag=back" method="post"
					onsubmit="return checkBack()">
					<table id="subtree1" style="DISPLAY:" width="100%" border="0"
						cellspacing="0" cellpadding="0">
						<tr>
							<td><table width="95%" border="0" align="center"
									cellpadding="5" cellspacing="0">
									<tr>
										<td height="20"><span class="newfont07">选择：<a
												href="#" class="right-font08" onclick="selectAll();">全选</a>-<a
												href="#" class="right-font08" onclick="unselectAll();">反选</a></span>
											<input name="submit" type="button" 
											value="车辆归队" onclick="save()"/></td>
									</tr>
									<tr>
										<td height="40" class="font42"><table width="100%"
												border="0" cellpadding="4" cellspacing="1" bgcolor="#464646"
												class="newfont03">

												<tr>
													<td colspan="5" bgcolor="#EEEEEE" class="tablestyle_title">
														<div align="center" style="font-size: 16px">车辆归队列表</div>
													</td>
												</tr>
												<tr bgcolor="#EEEEEE" height="30">
													<td width="5%" align="center">选择</td>
													<td width="25%" align="center">车牌号</td>
													<td width="25%" align="center">车辆型号</td>
													<td width="25%" align="center">出车人</td>
													<td width="25%" align="center">出车时间</td>
												</tr>
												<%
													int entityNumBegin = pageSize * (pageNow - 1);
													PreparedStatement pstmtEntities = null;
													if (query == null)
														pstmtEntities = con
																.prepareStatement("SELECT car.lpn,car.model,co.user,co.time FROM (select lpn,user,time FROM carry ORDER BY time DESC) AS co ,car WHERE car.lpn=co.lpn AND car.status=1 GROUP BY lpn LIMIT "
																		+ pageSize * (pageNow - 1) + "," + pageSize);
													else {
														pstmtEntities = con
																.prepareStatement("SELECT car.lpn,car.model,co.user,co.time FROM (select lpn,user,time FROM carry ORDER BY time DESC) AS co ,car WHERE co.lpn LIKE ? AND car.lpn=co.lpn AND car.status=1 GROUP BY lpn LIMIT "
																		+ pageSize * (pageNow - 1) + "," + pageSize);
														pstmtEntities.setString(1, "%" + query + "%");
													}
													rs = pstmtEntities.executeQuery();
													while (rs.next()) {
												%>
												<tr bgcolor="#FFFFFF" height="20">
													<td align="center"><input type="checkbox"
														name="backid" value="<%=rs.getString("lpn")%>" /></td>
													<td align="center"><%=rs.getString("lpn")%></td>
													<td align="center"><%=rs.getString("model")%></td>
													<td align="center"><%=rs.getString("user")%></td>
													<td align="center"><%=rs.getString("time")%></td>
												</tr>
												<%
													}
													rs.close();
												%>
											</table></td>
									</tr>
								</table></td>
						</tr>
					</table>
					<table width="95%" border="0" align="center" cellpadding="0"
						cellspacing="0">
						<tr>
							<td height="6"><img src="../images/spacer.gif" width="1"
								height="1" /></td>
						</tr>
						<tr>
							<td height="33"><table width="100%" border="0"
									align="center" cellpadding="0" cellspacing="0"
									class="right-font08">
									<tr>
										<td width="50%">共 <span class="right-text09"><%=pageTotal%></span>
											页 | 第 <span class="right-text09"><%=pageNow%></span> 页
										</td>
										<td width="49%" align="right">[<a href="?pageCar=1"
											class="right-font08">首页</a> | <a
											href="<%="?pageCar=" + ((pagePrev == 0) ? 1 : pagePrev)%>"
											class="right-font08">上一页</a> | <a
											href="<%="?pageCar=" + ((pageNext == 0) ? 1 : pageNext)%>"
											class="right-font08">下一页</a> | <a
											href="<%="?pageCar=" + pageTotal%>" class="right-font08">末页</a>]
											转至：
										</td>
										<td width="1%"><table width="20" border="0"
												cellspacing="0" cellpadding="0">
												<tr>
													<td width="1%"><input id="textfield3" name="textfield3" type="text"
														class="right-textfield03" size="1" id="jump_page" /></td>
													<td width="87%"><input name="Submit23222"
														type="button" class="right-button06" value=" "
														onclick="go()" /></td>
												</tr>
											</table></td>
									</tr>
								</table></td>
						</tr>
					</table>
				</form>
			</td>
		</tr>
	</table>
	<%
		con.close();
	%>
</body>
</html>